package com.gxa.p2p.service.impl;

import com.gxa.p2p.mapper.MassageMapper;
import com.gxa.p2p.pojo.Massage;
import com.gxa.p2p.service.MassageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

/**
 * @author R
 * @data 2021-10-26 18:48
 */
@Service
public class MassageServiceImpl implements MassageService {

    @Autowired
    MassageMapper massageMapper = null;


    @Override
    public void addMassage(Massage massage) {
        massage.setState(true);
        massage.setSendNum(0);
        massage.setCreatTime(new Timestamp(System.currentTimeMillis()));
        massageMapper.addMassage(massage);
    }

    @Override
    public List<Massage> findMassageByPage(String title, Boolean state, Integer page, Integer size) {
        List<Massage> massageByPage = massageMapper.findMassageByPage(title, state, (page - 1) * size, size);
        return massageByPage;
    }

    @Override
    public Integer findMassageCount(String title, Boolean state, Integer page, Integer size) {
        page = null;
        size = null;
        List<Massage> massageByPage = massageMapper.findMassageByPage(title, state, page, size);
        return massageByPage.size();
    }
}
